import request from '@/utils/request';
// 在非组件模块中获取store必须通过这种方式
import store from '@/store/'

// 登录
export const login = (data) => {
    return request({
        method: 'POST',
        url: '/app/v1_0/authorizations',
        data
    })
}

// 获取登录用户信息
export const userInfo = () => {
    return request({
        method: 'get',
        url: '/app/v1_0/user',
        headers: {
            Authorizations: `Bearer ${store.state.user.token}`
        }
    })
}
// 频道列表
export const getUserChannels = () => {
    return request({
        method: 'GET',
        url: "/app/v1_0/user/channels"
    })
}


// 获取文章列表
export const getArticles = (params) => {
    return request({
        method: 'GET',
        url: "/app/v1_1/articles",
        params
    })
}

// 获取所有频道
export const getAllchannels = () => {
    return request({
        method: "GET",
        url: "/app/v1_0/channels"
    })
}

// 添加频道列表
export const addUserChannel = data => {
    return request({
        method: "PATCH",
        url: "/app/v1_0/user/channels",
        data
    })
}

// 删除用户指定频道
export const deleteUserChannerl = channelId => {
    return request({
        method: "DELETE",
        url: `/app/v1_0/user/channels/${channelId}`
    })
}
